/**
 * Author by Cyrus
 * Date 2015-03-11
 * Contact xiaodpro@gmail.com
 */
var marker = (function(){
	function $(s){return "echo(\"" + s.replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + "\");"; };
	return function(v, m){
		var s = v.split(/(<%\-\-|\-\-%>|<%|%>)/g), r = /\$\{[^\}]+\}/g,
			w = "var echo=(function(){var w='';return function(s){if(s==undefined)return w;w+=s;};})();with(m){";
		for(var i = 0; i < s.length; i++){
			var n = s[i];
			if(n == "<%--") while((++i<s.length) && ((n=s[i])!="--%>"));
			else if(n == "<%") w += s[++i];
			else if(n != "%>"){
				if(!n.match(r)) w += $(n);
				else{
					var nm = n.match(r), ns = n.split(r);
					w += $(ns[0]);
					for(var j = 0; j < nm.length; j++){
						w += "echo(" + nm[j].replace(/(\$\{|\})/g, "") + ");";
						w += $(ns[j+1]);
					}
				}
			}
		}
		var fn = new Function("m", w + "}return echo();");
		if(m === undefined)
			return {"render": fn};
		return fn(m||{});
	};
})();
///~
